package org.csu.mypetstore.service.impl;

import org.csu.mypetstore.domain.Product;
import org.csu.mypetstore.persistence.ProductMapper;
import org.csu.mypetstore.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductMapper productMapper;

    @Override
    public Product getProduct(String productId) {
        return productMapper.getProduct(productId);
    }

    @Override
    public List<Product> getProductListByCategory(String categoryId) {
        return productMapper.getProductListByCategory(categoryId);
    }

    @Override
    public List<Product> searchProductList(String keyword) {
        return productMapper.searchProductList(keyword);
    }

    @Override
    public String addProduct(Product product) {
        try{
            productMapper.addProduct(product);
            return "Succeed in Adding Product";
        }catch (Exception e)
        {
            e.printStackTrace();
            return "Failed in Adding Product";
        }
    }

    @Override
    public String deleteProduct(String productId) {
        try{
            productMapper.deleteProduct(productId);
            return "Succeed in Deleting Product";
        }catch (Exception e)
        {
            e.printStackTrace();
            return "Failed in Deleting Product";
        }
    }

    @Override
    public String updateProduct(Product product) {
        try{
            productMapper.updateProduct(product);
            return "Succeed in Updating Product";
        }catch (Exception e)
        {
            e.printStackTrace();
            return "Failed in Updating Product";
        }
    }
}
